package com.huiyujiaoyu.powertime.ui.login;


import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.widget.ImageView;

import com.huiyujiaoyu.base.BaseActivity;
import com.huiyujiaoyu.powertime.MainActivity;
import com.huiyujiaoyu.powertime.R;
import com.huiyujiaoyu.powertime.model.UserInfoBean;
import com.huiyujiaoyu.util.ActivityUtil;

import butterknife.BindView;


public class SplashActivity extends BaseActivity {
    @BindView(R.id.iv_bg)
    ImageView mIvBg;

    @Override
    protected void initView() {
         ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mIvBg,"alpha",0.3f, 1.0f);
         objectAnimator.setDuration(3000);
         objectAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                    doFinish();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        objectAnimator.start();
    }


    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }
    private void doFinish() {
        //如果第一次打开就跳转到
        if(UserInfoBean.getInstance().isFirstOpen()){
            Intent intent = new Intent(this, GuidePageActivity.class);
            startActivity(intent);
        }else if(UserInfoBean.getInstance().isLogin()){
            if(TextUtils.isEmpty(UserInfoBean.getInstance().getGender())){
                ActivityUtil.startActivity(mContext,MainActivity.class);
            }else{
                ActivityUtil.startActivity(mContext,MainActivity.class);
            }
        }else{
            //如果没有登录就跳转到登录页
            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
        }
        finish();
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {

        }
        return false;

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

}
